from django.test import TestCase

# Create your tests here.

# from app01.models import Comment
# import django
# django.setup()
#
# def find_root_comment(comment: Comment):
#     if comment.parent_comment:
#         return find_root_comment(comment.parent_comment)
#     return comment
#
#
#     comment_dict = {}
#
#     # 找到某个文章的所有评论
#     comment_query = Comment.objects.filter(article_id=1)
#     for comment in comment_query:
#         # 如果父亲是None，就说明是很评论
#         if not comment.parent_comment:
#             # 把评论放入字典
#             comment_dict[comment.id] = comment
#             # 给根评论添加自定义属性，将所有的子评论放进去
#             comment.sub_comment = []
#             continue
#
#         # 一定是某个父评论的子评论
#         for sub_comment in comment.comment_set.all():
#             # 遍历
#             root_comment = find_root_comment(sub_comment)
#             comment_dict[root_comment.nid].sub_comment.append(sub_comment)
#
#         for k, v in comment_dict.items():
#             print(v, '很评论')
#             for comment in v.sub_comment:
#                 print('  ', comment, '子评论')

















